package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.query.RegionQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRegionService;
import cn.wolfcode.luowowo.common.util.AJaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author hslef
 */
@Controller
@RequestMapping("region")
public class RegionController {
    @Reference
    private IRegionService regionService;

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQuery qo){
        qo.setOrderBy("sequence asc");
        PageInfo<Region> pageInfo = regionService.listAll(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "region/list";
    }

    @RequestMapping("changeHotValue")
    @ResponseBody
    public AJaxResult changeHotValue(int hot, Long id){
        regionService.changeHotValue(hot,id);
        return AJaxResult.SUCCESS();
    }

    @RequestMapping("getDestByRegionId")
    @ResponseBody
    public List<Destination> getDestByRegionId(Long rid){

        return regionService.getDestByRegionId(rid);
    }

    @RequestMapping("getDestByDeep")
    @ResponseBody
    public List<Destination> getDestByDeep(Integer deep){
        return destinationService.getDestByDeep(deep);
    }

    @RequestMapping("delete")
    @ResponseBody
    public AJaxResult delete(Long id){
        regionService.delete(id);
        return AJaxResult.SUCCESS();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public AJaxResult saveOrUpdate(Region region){
        regionService.saveOrUpdate(region);
        return AJaxResult.SUCCESS();
    }
}
